import routerConfig from '../../page/router';
import routerInit from 'miniapp-router';
Component({
  mixins: [],
  data: {
    listData: [],
    mlin: false,
    total: 0,
    nick: '',
    video: '',
    sales_id:'',
    page: 1,
    pagesize: 10
  },
  props: {},
  didMount() {
    routerInit.call(this, routerConfig);  //跳转页面初始化
    this.getaty(0);
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    //关闭视频模态框
    closeVideo(e) {
      this.setData({
        mlin: false,
        vdUrl: '',
      });
    },
    //预览视频
    openVideo(e) {
      var x = e.currentTarget.dataset.x;
      this.setData({
        mlin: true,
        sales_id: x.record.sales_id
      });
    },
    //打开详情页
    openDes(evt){
      let $router = this.$page.$router;
      console.log(evt)
      var x = evt.currentTarget.dataset.x;
      var id = x.record.sales_id;
      console.log(id)
      $router.push(`/component/act-des/${id}`);
    },
    //通知会员
    openMember(evt){
      let $router = this.$page.$router;
      console.log(evt)
      var x = evt.currentTarget.dataset.x;
      var id = x.record.sales_id;
      var title = x.record.title;
      console.log(id)
      console.log(title)
      $router.push(`/component/act-member/${title}/${id}`);
    },
    getaty(pageNum) {
      var apiurl = 'App.ShopRedsSales.GetLists';
      var params = {
        "page": pageNum,
        "pagesize": this.data.pagesize,
      };
      var app = getApp();
      var self = this;
      app.xdapis(apiurl, params, function (e) {
        my.hideLoading();
        //my.alert({ title: JSON.stringify(e) });
        console.log(55555555555)
        console.log(e)
        self.setData({
          listData: e.list,
          total: e.page_info.total
        });
      });
    },
    onChange(e) {
      let {
        detail: { value },
        currentTarget: { dataset }
      } = e;
      let { name } = dataset;
      console.log(name + ' onChange:', value);
      this.setData({ [name]: value });
    },
    handleStart(evt) {
      var x = evt.currentTarget.dataset.x;
      var self = this;
      my.confirm({
        title: '确认',
        content: '需要开启活动吗?',
        success: (result) => {
          if (result.confirm) {
            var apiurl = 'App.ShopRedsSales.ModifyStatus';
            var params = {
              "sales_id": x.record.sales_id,
              "status": 2
            };
            console.log(2222222222)
            console.log(params)
            var app = getApp();
            app.xdapis(apiurl, params, function (e) {
              my.hideLoading();
              my.showToast({ content: '开启成功!' });
              self.getaty(1);
            });
          }
        }
      });
    },
    atysave(evt) {
      if (!this.data.nick) {
        my.alert({ content: '淘宝用户名不能为空!' });
        return false;
      }
      if (!this.data.video) {
        my.alert({ content: '视频地址不能为空!' });
        return false;
      }
      //var x = evt.currentTarget.dataset.x;
      //my.alert({ title: x.record.sales_id });
      var apiurl = 'App.ShopRedsMiniApp.ApplySales';
      var params = {
        "nick": this.data.nick,
        "video": this.data.video,
        "sales_id": this.data.sales_id,
        "platform_id": 1,
        "user_id": 1,
        "apply_user_id": 1,
        "video_cover": 'https://jcb001.oss-cn-shanghai.aliyuncs.com/LOGO.png',
        "duration": 15,
        "return_format": 'taobao',
      };
      var app = getApp();
      var that =  this;
      app.xdapis(apiurl, params, function (e) {
        my.hideLoading();
        my.showToast({ content: '模拟成功，视频已添加到该活动下面!' });
        that.setData({
          mlin: false
        });
        that.getaty(1);
      });
    },
    handleStop(evt) {
      var x = evt.currentTarget.dataset.x;
      var self = this;
      my.confirm({
        title: '确认',
        content: '真的要暂停活动吗?',
        success: (result) => {
          if (result.confirm) {
            var apiurl = 'App.ShopRedsSales.ModifyStatus';
            var params = {
              "sales_id": x.record.sales_id,
              "status": 3
            };
            var app = getApp();
            app.xdapis(apiurl, params, function (e) {
              my.hideLoading();
              my.showToast({ content: '暂停成功!' });
              self.getaty(1);
            });
          }
        }
      });
    },
    handleDel(evt) {
      const { id } = evt.target.dataset;
      var self = this;
      my.confirm({
        title: '确认',
        content: '真的要删除吗?',
        success: (result) => {
          if (result.confirm) {
            var apiurl = 'App.ShopRedsSales.ModifyStatus';
            var params = {
              "sales_id": id,
              "status": 0
            };
            var app = getApp();
            app.xdapis(apiurl, params, function (e) {
              my.hideLoading();
              my.showToast({ content: '删除成功!' });
              self.getaty(1);
            });
          }
        }
      });
    },
    getPageData(current, e) {
      this.getaty(current.detail.value);
    }
  }
});
